home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / UTIL / CD Playthrough 1.5.sit / CD Playthrough 1.5 / Source / SoundOut.c < prev    next >
Text File  |  1996-11-20  |  3KB  |  106 lines

  1. //    CD Playthrough
  2. //    Version: 1.5 <October 3, 1994>
  3. //    (c)    1994 neg.active.productions, jwang@csua.berkeley.edu <James    Wang>  
  4. //    ftp://ftp.csua.berkeley.edu/pub/jwang/cool/cd-playthrough-15.hqx
  5.  
  6. //    File:            SoundOut.c
  7. //
  8. //    Contains:        Sound output sub-routines
  9. //
  10. //    Written by:        Gary, Anwyl, James Wang
  11. //
  12. //    Description:    Searches for the 'sdev' sound component, create an instance and
  13. //                    references it for getting and setting the sound out rate option.
  14.  
  15.  
  16. #include "main.h"
  17.  
  18.  
  19. void open_sdev_component(ComponentInstance *compInst)
  20. {
  21.     OSErr                    err;
  22.     Component                comp;
  23.     ComponentDescription    compDesc0, compDesc1;
  24.     Handle                    nameHandle;
  25.  
  26.     // Allocate a handle for the name
  27.     nameHandle = NewHandle(256);
  28.     if (nameHandle == 0) stop_alert(MemFull);
  29.     HLock(nameHandle);
  30.  
  31.     // Search all 'sdev' components for the "Built-In" sound driver
  32.     compDesc0.componentType = 'sdev';
  33.     compDesc0.componentSubType = 0;
  34.     compDesc0.componentManufacturer = 0;
  35.     compDesc0.componentFlagsMask = 0;
  36.  
  37.     comp = 0;
  38.     while (1) {
  39.         comp = FindNextComponent(comp, &compDesc0);
  40.         if (comp == 0) stop_alert(soCompNotFound);    // empty or exhausted component list
  41.  
  42.         err = GetComponentInfo(comp, &compDesc1, nameHandle, 0, 0);
  43.         if (err != noErr) stop_alert(GetCompInfoFailed);
  44.  
  45.         // nameHandle is a pascal string. See if it is "¥pBuilt-in"
  46.         if (EqualString("¥pBuilt-in", *((StringHandle)nameHandle), TRUE, FALSE))
  47.             break;
  48.     }
  49.  
  50.     HUnlock(nameHandle);
  51.     DisposeHandle(nameHandle);
  52.  
  53.     // Open the sound component
  54.     *compInst = OpenComponent(comp);
  55.     if (*compInst == 0) stop_alert(OpenCompFailed);
  56. }
  57.  
  58. Boolean desired_rate_available(UnsignedFixed myWantRate)
  59. {
  60.     int                 i;
  61.     OSErr                err;
  62.     ComponentInstance    compInst;
  63.     SRCInfoStruct        srcInfo;
  64.  
  65.     open_sdev_component(&compInst);
  66.     err = SoundComponentGetInfo(compInst, 0, siSampleRateAvailable, &srcInfo);
  67.     CloseComponent(compInst);
  68.     if (err != noErr) stop_alert(soGetCompInfoFailed);
  69.     
  70.     if (srcInfo.count == 0)  {
  71.         // The lower and upper bounds of a range was returned.
  72.         if ((*srcInfo.rates)[0] < myWantRate && (*srcInfo.rates)[1] > myWantRate)
  73.             return TRUE;
  74.     }
  75.     else  {
  76.         // An array of available rates was returned
  77.         for (i=0; i<srcInfo.count; i++)
  78.             if ((*srcInfo.rates)[i] == myWantRate)
  79.                 return TRUE;
  80.     }
  81.  
  82.     return FALSE;
  83. }
  84.  
  85. void get_sound_out(SoundSetting *mySnd)
  86. {
  87.     OSErr                err;
  88.     ComponentInstance    compInst;
  89.  
  90.     open_sdev_component(&compInst);
  91.     err = SoundComponentGetInfo(compInst, 0, siSampleRate, &(mySnd->soCurrRate));
  92.     CloseComponent(compInst);
  93.     if (err != noErr) stop_alert(soGetCompInfoFailed);
  94. }
  95.  
  96. void set_sound_out(SoundSetting *mySnd)
  97. {
  98.     OSErr                err;
  99.     ComponentInstance    compInst;
  100.  
  101.     open_sdev_component(&compInst);
  102.     err = SoundComponentSetInfo(compInst, 0, siSampleRate, (void *)mySnd->soWantRate);
  103.     CloseComponent(compInst);
  104.     if (err != noErr) stop_alert(soSetCompInfoFailed);
  105. }
  106.